package tungsten.pb;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import tungsten.base.BaseApp;
import tungsten.base.SpringContext;
import tungsten.base.thread.ThreadPool;
import tungsten.pb.module.Module;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * Created by Lv on 2016/6/24.
 */
public class PBApp extends BaseApp
{
    private PBServer server;

    @Autowired
    @Qualifier("thread.message.count")
    private Integer messageThread = 4;

    @Override
    protected void initConfig()
    {
        super.initConfig();
        server = new PBServer();
    }

    public PBApp listener(int port)
    {
        server.listener(port);

        return this;
    }

    @Override
    protected void initThread()
    {
        super.initThread();
        ThreadPool.initThread(Module.MESSAGE_THREAD,messageThread, messageThread,0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
    }

    @Override
    protected void onExit()
    {
        super.onExit();
        server.dispose();
    }
}